<?php
use Workerman\Worker;
use \Workerman\Lib\Timer;
require_once __DIR__ . '/../vendor/autoload.php';

$worker = new Worker('tcp://0.0.0.0:8484');

$worker->count = 1;
$worker->onWorkerStart = function($worker)
{
    //每2.5秒执行一次
};



$worker->onConnect = function($connection)
{

	$time_interval = 2.5;
    Timer::add($time_interval, function() use ($connection)
    {
      	   $connection->send(date("Y-m-d:H:i:s"));
    });



    $connection->onClose = function($connection)
    {
        echo "connection closed\n";
    };
};


$worker->onMessage = function($connection, $data)
{
    var_dump($data);
    $connection->send($data);
};
// 运行worker
Worker::runAll();